<?php
import('Database.Dal.~');

class Article{

	private $nameInBase = 'article';
	private $db;

	public function __construct(){
		$this->db = Hoa_Database_Dal::getInstance('myConn');
	}

	public function addArticleInBdd($params){

	}

	public function deleteArticleInBDD($id){
		try {
			$this->fram->db->beginTransaction();
			$this->fram->db->query('DELETE FROM '.$nameInBase.' WHERE id = '.$id);
			$this->fram->db->commit();
		} catch ( Hoa_Database_Dal_Exception $e ) {
			$this->fram->db->rollBack();
			$e->raiseError();
		}
	}

	public function updateArticleInBDD($param){
		try {
			$this->fram->db->query('UPDATE FROM '.$this->nameInBase.' SET '.$newValue.' WHERE id = '.$param['id']);
		} catch ( Hoa_Database_Dal_Exception $e ) {
			$e->raiseError();
		}
	}

	public function showAllArticles(){
		$statement = null;
		try {
			$statement = $this->db->query('SELECT SQL_CACHE id, titre, texte FROM '.$this->nameInBase.' ORDER BY id DESC');
			if(DEBUG) {
				echo '<pre>';
					print_r($statement->fetchAll());
				echo '</pre>';
			}
			return $statement->fetchAll();
		} catch ( Hoa_Database_Dal_Exception $e ) {
			$e->raiseError();
		}


	}

}

?>